<!DOCTYPE html>
<html>
<head>
<title>When creating an import, use the registry of the master document</title>
<meta name="author" title="Sergey G. Grekhov" href="mailto:sgrekhov@unipro.ru">
<meta name="assert" content="When creating an import, use the registry of the master document.">
<link rel="help" href="http://www.w3.org/TR/custom-elements/#creating-and-passing-registries">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../testcommon.js"></script>
<link rel="stylesheet" href="/resources/testharness.css">
</head>
<body>
<div id="log"></div>
<script>
var test1 = async_test('Registry of the imported document should be shared with master document. ' +
    'Import is asynchronous');
test1.step(function() {
    var iframe = newIFrame('../resources/import-master-async.html');
    document.body.appendChild(iframe);
    iframe.onload = test1.step_func(function() {
        var doc = iframe.contentDocument;
        var link = doc.querySelector('link[rel=import]');
        link.onload = test1.step_func(function() {
            try {
                var doc2 = link.import;
                var name = 'x-frame';
                doc.registerElement(name);
                assert_throws(
                    'NotSupportedError',
                    function() { doc2.registerElement(name); },
                    'Registering a custom element type name that is already registered in a shared ' +
                        'registry should throw an exception');
                test1.done();
            } finally {
                iframe.remove();
            }
        });
    });
});


var test2 = async_test('Registry of the master document should be shared with imported document. ' +
    'Import is asynchronous');
test2.step(function() {
    var iframe = newIFrame('../resources/import-master-async.html');
    document.body.appendChild(iframe);
    iframe.onload = test2.step_func(function() {
        var doc = iframe.contentDocument;
        var link = doc.querySelector('link[rel=import]');
        link.onload = test2.step_func(function() {
            try {
                var doc2 = link.import;
                var name = 'x-frame';
                doc2.registerElement(name);
                assert_throws(
                    'NotSupportedError',
                    function() { doc.registerElement(name); },
                    'Registering a custom element type name that is already registered in a shared ' +
                        'registry should throw an exception');
                test2.done();
            } finally {
                iframe.remove();
            }
        });
    });
});


testInIFrame('../resources/import-master.html', function(doc) {
    var link = doc.querySelector('link[rel=import]');
    var doc2 = link.import;
    var name = 'x-frame';
    doc.registerElement(name);
    assert_throws(
        'NotSupportedError',
        function() { doc2.registerElement(name); },
        'Registering a custom element type name that is already registered in a shared ' +
            'registry should throw an exception');
}, 'Registry of the imported document should be shared with master document. Import is syncronous');


testInIFrame('../resources/import-master.html', function(doc) {
    var link = doc.querySelector('link[rel=import]');
    var doc2 = link.import;
    var name = 'x-frame';
    doc2.registerElement(name);
    assert_throws(
        'NotSupportedError',
        function() { doc.registerElement(name); },
        'Registering a custom element type name that is already registered in a shared ' +
            'registry should throw an exception');
}, 'Registry of the master document should be shared with imported document. Import is syncronous');
</script>
</body>
</html>
